// 新的声明方式 
// var let const
var _var = 'val';
let _let = 'let';
const _const = 'const';



/* 
 * 解构赋值
 * 数组、对象、字符串
 * 函数解构
 */
let [aa, bb, cc] = [1, 2];
let {oa, ob = 1} = {oa: 1, ob: undefined} // undefined和null的区别
// let foo;
// {foo} = {foo: 'lee yangyang'}
let [a, b, c] = 'lee';
let adds = ([a, b]) => a + b;




// 扩展运算符...arg
// 扩展运算符的用处
// rest运算符 (注意不能后面跟有参数)
let arg = (...arg) =>{
    return arg[0] + arg(1);
}
let arr1 = ['lee','yangyang'];
let arr2 = [...arr1];
// arr2.push("lee yangyang");
// console.log(arr2)
// console.log(arr1)
let rest = (...rst) =>{
    let sum=0;
    for(var val of rst){
        sum+=val;
    }
    return sum;
}
// console.log(rest(1, 2, 3));




/* 字符串模板 || 字符串查找
 * includes 包含
 * starsWith 开头包含
 * endsWith 结尾包含
 * repeat 复制
 */
let str = "yangyang lee";
let txt = `hello ${str}`;
let _a = 1;
let _b = 2;
let result = `${_a+_b}`;
str.includes(str);
// console.log(str.repeat(3));




// ES6数字操作
/*
 * isFinite 数字判断和转换
 * isNaN 特殊的非数字
 * isInteger 判断是否为整数
 * parseInt 转化整数
 * 取值范围 math...
 * 最大安全整数MAX_SAFE_INTEGER
 * 最小安全整数Min_SAFE_INTEGER
 * 判断安全整数isSafeInteger
 */
let lee = Number.isFinite(12.1);
let lee1 = Number.isNaN(NaN);
let lee2 = Number.isNaN(12.1);
let lee3 = Number.isNaN(12.1);
let lee4 = Math.pow(2, 53) - 1;
let lee5 = Number.MAX_SAFE_INTEGER;
let lee6 = Number.Min_SAFE_INTEGER;
Number.isSafeInteger(lee5);
// console.log(lee3);




// ES6中新增的数组知识
// form, of
// find, findIndex, fill (实例方法)
// for of , foreach, filter, some, map遍历
// in的用法
let json = {
    "0": "lee",
    "1": "yangyang",
    length: 2
}
let arr_from = Array.from(json);
let arr_of = Array.of(1,2,3,4);
let arr_find = [1, 2, 3, 4, 5, 6];
let afind = arr_find.find((value)=>{value > 5});
let afill = arr_find.fill('lee', 2, 4);
for (let item of arr_find){
    // console.log(item)
}
let kk = arr_find.filter(x=> x > 4);
let arr_in = 1 in arr_find;



// ES6中的箭头函数和扩展
let add = function(a, b) {
    'use strict'
    // 主动抛出错误
    if(a==0){
        throw new Error('ni cuo le !')
    }
    return a + b;
}
// let add = (a, b = 2) => a + b;
// console.log(add(1, 2));



// ES6中对象
// 对象赋值 , key键赋值, 对象对比（Object.is）,合并对象（Object.assign）
let obj1 = {name:'lee'};
let obj2 = {name:'lee'};




// 用Proxy进行预处理
// new Proxy({},{}); get, set, apply
let pxy = new Proxy(
    {
        add:(a) => a + 1,
        name: 'lee'
    },
    {
        get:(target, key, property)=>{
            console.log('first see me');
            return target[key];
        }
    }
)
// console.log(pxy.name);

//promise对象的使用
let states = 1;
function step1(resolve, reject){
    if(states == 1){
        resolve('1.跳伞');
    }else{
        reject('跳伞出错');
    }
}
function step2(resolve, reject){
    if(states == 1){
        resolve('2.打开降落伞');
    }else{
        reject('打开降落伞出错');
    }
}
new Promise(step1).then((v)=>{
    // console.log(v);
    return new Promise(step2);
}).then(v=>{
    // console.log(v);
})


// 模块化操作 export, import, as的用法， export defalut
